/**
 * @filename UserService.java
 * @package com.tianjian.dass.service.system[MySSM]
 * @description 用户信息
 * @author 胡正衛
 * @date 2012-6-6 上午10:17:41
 * @version v0.1
 */
package com.tianjian.oa.system.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tianjian.common.Criteria;
import com.tianjian.oa.system.mapper.UserMapper;
import com.tianjian.oa.system.pojos.UserInfo;

/**
 * @author 胡正衛
 */
@Service
public class UserService {

	@Autowired
	private UserMapper userMapper;

	/**
	 * 获取用户列表
	 * @param criteria
	 * @return
	 */
	public List<UserInfo> getData(Criteria criteria) throws Exception {
		return userMapper.getData(criteria);
	}
	
	/**
	 * 获取对应角色用户列表
	 * @param criteria
	 * @return
	 */
	public List<UserInfo> getYiyData(Criteria criteria) throws Exception{
		return userMapper.getYiyData(criteria);
	}

	/**
	 * 获取用户总数
	 * @param criteria
	 * @return
	 */
	public int getCount(Criteria criteria) {
		try {
			return userMapper.getCount(criteria);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	
	/**
	 * 获取用户总数
	 * @param criteria
	 * @return
	 */
	public int getYiyCount(Criteria criteria) {
		try {
			return userMapper.getYiyCount(criteria);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	/**
	 * 添加用户
	 * @return
	 */
	public int add(UserInfo userInfo) {
		try {
			return userMapper.insert(userInfo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	/**
	 * 编辑用户资料
	 * @return
	 */
	public int edit(UserInfo userInfo) {
		try {
			return userMapper.update(userInfo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	/**
	 * 停用或启用用户
	 * @param id
	 * @param enable
	 * @return
	 */
	public int enable(int id, boolean enable) {
		try {
			return userMapper.enable(id, enable ? 0 : 1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	/**
	 * 删除用户
	 * @return
	 */
	public int del(int id) {
		try {
			return userMapper.delete(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	public int selectBh() {
		return userMapper.selectBh();
	}
}
